<?
if(REWRITE_ON){
	ob_start();//start buffering//@ob_start('ob_gzhandler');
}

require_once ROOT_PATH.'core/AutoLoader.php';
require_once ROOT_PATH . 'core/SohaPayment.php';
CGlobal::$my_server				=	$server_list;
CGlobal::$img_server			=	$img_server;
CGlobal::$storage_server		=	$storage_server;
CGlobal::$email_dev             =   $email_dev;
CGlobal::$mail_sting_server     =   $mail_sting_server;

$lIsSearchE = ECLib::is_search_engine();

if(MEMCACHE_ON){
	CGlobal::$memcache_server = $memcache_server;
}
if(REDIS_ON){
    CGlobal::$redis_cf              =   $redis_cf;
}
if(MONGO_ON){
    CGlobal::$mongo_cf              =   $mongo_cf;
}
unset($memcache_server,$server_list,$img_server,$storage_server);

//my server 

if(isset($_REQUEST['trigger']) && (int)$_REQUEST['trigger']==1){
	ArrCache::del_cache();
	ECCache::auto_delete();
	StaticCache::delCache();
	ECore::del_page_cache();
	exit;
}

if(isset($_GET['page']) && $_GET['page']=='error'){
	define('ERROR_PAGE',1);
}
else{
	define('ERROR_PAGE',0);
}

if(!$lIsSearchE && !defined('NO_SESSION') && !ERROR_PAGE)
{
	if(SESSION_TYPE == 'db')
	{
		require_once ROOT_PATH.'includes/session.class.php';//Session db store
	}
	elseif(SESSION_TYPE == 'memcache')
	{
		require_once(ROOT_PATH."includes/session.memcache.php");//Session memcache store
	}
	else
	{		
		session_start(); 
	}
}

// Disable ALL magic_quote
//set_magic_quotes_runtime(0);

ini_set("magic_quotes_runtime", 0);

if (get_magic_quotes_gpc())
{
	function stripslashes_deep($value){
		$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
		return $value;
	}
	
	$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
	$_COOKIE  = array_map('stripslashes_deep', $_COOKIE);
}

if(!ERROR_PAGE)
{
	################################################################################################
	if(!User::is_login())
	{
		if(isset($_COOKIE['ecore_id']) && isset($_COOKIE['password']))
		{
			User::check_cookie_login($_COOKIE['ecore_id'],$_COOKIE['password']);
		}
		else
		{
			ECLib::my_setcookie('ecore_id',"",TIME_NOW-3600);
			ECLib::my_setcookie('password',"",TIME_NOW-3600);
		}
	}
	else
	{
		if(isset($_GET['login_as'])||isset($_GET['login_as_id']))
		{
			if(User::is_admin())
			{
				$user_id = (int)Url::get('login_as_id',0);
				$user 	 = array();
				
				if($user_id){
					$user = User::getUser($user_id);
				}
				else{
					$user_email = Url::get('login_as');
					if($user_email!=''){
						$user = User::getByEmail($user_email);
					}
				}

				if ($user)
				{
					if(User::is_root()  || !$user['gids'] || ($user['gids'] && !preg_match("/([\D])9([\D])/i","|{$user['gids']}|")))
					{
						User::LogIn($user);
					}
				}
			}
			
			Url::redirect_url(Url::build_all(array('login_as','login_as_id')));
		}
	}
	################################################################################################
}

CGlobal::$keywords  = "RoyalFoodCourt";

CGlobal::$meta_desc = "RoyalFoodCourt";

CGlobal::$website_title = "RoyalFoodCourt";


//Tiền tệ:
CGlobal::$currency = array('1'=>'VNĐ');//CGlobal::$currency = array('1'=>'VNĐ','2'=>'$','3'=>'€');//'3'=>'&euro;');

register_shutdown_function(array("DB","close"));
register_shutdown_function(array("Upload","storage_close"));

		
global $display;
$display = new ECDisplay();
?>